package org.edu.modules.kwgl.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import org.apache.ibatis.annotations.Param;
import org.edu.modules.kwgl.entity.VeJwBukao;
import org.edu.modules.kwgl.entity.VeJwKaoshi;
import org.edu.modules.kwgl.entity.VeJwKsJiankao;
import org.edu.modules.kwgl.entity.VeJwKssjd;
import org.edu.modules.kwgl.mapper.VeJwKaoshiMapper;
import org.edu.modules.kwgl.service.IVeJwKaoshiService;
import org.edu.modules.scheduleCommon.dto.BasePageDto;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Description: 考试信息
 * @Author: jeecg-boot
 * @Date:   2021-05-07
 * @Version: V1.0
 */
@Service
public class VeJwKaoshiServiceImpl extends ServiceImpl<VeJwKaoshiMapper, VeJwKaoshi> implements IVeJwKaoshiService {

    @Override
    public IPage<VeJwKaoshi> pageDto(BasePageDto page, @Param(Constants.WRAPPER)  Wrapper queryWrapper) {
        return baseMapper.pageDto(page, queryWrapper);
    }

    @Override
    public void updateStatusByIds(String ids, int status) {
        List<String> list = Arrays.asList(ids.split(","));
        for (String str:list) {
            baseMapper.updateById(new VeJwKaoshi().setId(Integer.parseInt(str)).setStatus(status));
        }

    }

    @Override
    public void changePublishById(int id, int ispublish) {
        baseMapper.updateById(new VeJwKaoshi().setId(id).setIspublish(ispublish));
    }

    @Override
    public VeJwKaoshi getByKcid(int kcid) {
        return baseMapper.selectOne(new QueryWrapper<VeJwKaoshi>()
                .eq("kcId",kcid)
                .eq("isPublish",1)
                .orderByDesc("createTime")
                .last("LIMIT 1"));
    }

    @Override
    public VeJwKaoshi getBySemidAndKcidAndBjid(Integer semid, Integer kcid, String bjid) {
        LambdaQueryWrapper<VeJwKaoshi> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(VeJwKaoshi::getSemid, semid);
        wrapper.eq(VeJwKaoshi::getKcid, kcid);
        wrapper.eq(VeJwKaoshi::getBjid, bjid);
        return this.getOne(wrapper);
    }
}
